#define DEBUG
#include <cstdio>
#include <cstring>
#define MAXK 9
#define INF 0x7ffffffffffffff

using namespace std;

long long min(long long a, long long b) {
  return a<b ? a : b;
}

int main() {
#ifdef DEBUG
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
#endif

  static long long w[(1<<MAXK)+1][(1<<MAXK)+1], f[MAXK+1][(1<<MAXK)+1][(1<<MAXK)+1];
  int K;
  scanf("%d", &K);
  for (int i=1; i<=(1<<K); i++) {
    for (int j=1; j<=(1<<K); j++) {
      scanf("%lld", &w[i][j]);
    }
  }

  for (int i=0; i<=K; i++) {
    for (int j=0; j<=1<<K; j++) {
      for (int k=0; k<=1<<K; k++) {
	f[i][j][k] = INF;
      }
    }
  }
  long long ans=INF;
  for (int i=1; i<=1<<K; i++) {
    f[K][i][i]=0;
  }
  for (int i=K-1; i>=0; i--) {
    for (int t=0; t<(1<<i); t++) {
      for (int j=t*(1<<(K-i))+1; j<=(t+1)*(1<<(K-i)); j++) {
	for (int k=t*(1<<(K-i))+1; k<=(t+1)*(1<<(K-i)); k++) {
	  if (j!=k) {
	    for (int x=t*(1<<(K-i))+1; x<=(t+1)*(1<<(K-i)); x++) {
	      if ((x!=j && x!=k)||i==K-1) {
		for (int y=t*(1<<(K-i))+1; y<=(t+1)*(1<<(K-i)); y++) {
		  if ((y!=j && y!=k)||i==K-1) {
		    if (x!=y) {
		      f[i][j][k] = min(f[i][j][k], f[i+1][j][x]+f[i+1][y][k]+w[x][y]);
		    }
		  }
		}
	      }
	    }
	    if (!i) {
	      ans = min(ans, f[i][j][k]);
	    }
	  }
	}
      }
    }
  }
  printf("%lld", ans);

  fcloseall();
  return 0;
}
